package com.example.demo.service.serviceimpl;

import com.example.demo.dao.CommentDao;
import com.example.demo.entity.CommentEntity;
import com.example.demo.service.CommentService;
import com.example.demo.vo.CommentVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Resource
    CommentDao commentDao;

    @Override
    public List<CommentEntity> getCommentsByProductId(int products_id) {
        return commentDao.getCommentsByProductId(products_id);
    }

    @Override
    public List<CommentEntity> getCommentsByUserId(int user_id) {
        return commentDao.getCommentsByUserId(user_id);
    }

    @Override
    public int addComment(CommentVo commentVo) {
        return commentDao.addComment(commentVo);
    }

    @Override
    public int updateComment(CommentVo commentVo) {
        return commentDao.upComment(commentVo);
    }

    @Override
    public int deleteComment(int id) {
        return commentDao.delComment(id);
    }

    @Override
    public CommentEntity getCommentById(int id) {
        return commentDao.getCommentById(id);
    }

    @Override
    public double getAverageRatingByProductId(int products_id) {
        Double avgRating = commentDao.getAverageRatingByProductId(products_id);
        return avgRating != null ? avgRating : 0.0;
    }

    @Override
    public int delCommentUserId(int user_id) {
        return commentDao.delCommentUserId(user_id);
    }

}